import {
  Column,
  Entity,
  PrimaryGeneratedColumn,
  OneToMany,
  OneToOne,
  JoinColumn,
  BaseEntity,
  ManyToOne,
  CreateDateColumn,
} from 'typeorm';

//import { PhotoEntity } from '../photo/photo.entity';
import { Exclude } from 'class-transformer';
import { Role } from '../role/entities/role.entity';
@Entity({ name: 'users' }) //数据表的名字
export class UsersEntity extends BaseEntity {
  @PrimaryGeneratedColumn() //设置主键和自增
  id: number;

  @Column() //字段及相关限制
  username: string;

  @Column({ select: false }) //字段及相关限制
  @Exclude()
  password: string;
  @Column({ default: '' }) //字段及相关限制
  email?: string;
  @Column({ default: '' }) //字段及相关限制
  type?: string;
  @ManyToOne((type) => Role, (role) => role.users)
  role: Role;
  @CreateDateColumn({
    type: 'timestamp',
    name: 'cgdate',
    default: () => 'CURRENT_TIMESTAMP(6)',
    comment: '创建时间',
    select: false,
  }) //字段及相关限制
  cgdate: string;

  /*  /!*@Column() //字段及相关限制
  hit: number;*!/
  /!*    @Column({ length: 32, select: false })
      content: string;
      @Column({ default: 1 })
      curdate: string;*!/
    /!*!//一对多关系
    @OneToMany(() => PhotoEntity, (photo) => photo.user)
    : [];*!/!*!/*/
}
